class Person {
  @State name: string;

  constructor(name: string) {
    this.name = name
  }
}

function State(target: object, key: string) {
  let value: any;

  Object.defineProperty(target, key, {
    set (newValue) {
      value = newValue
      console.log(`监视到修改${key}属性为${newValue}`)
    },
    get () {
      console.log(`监视到读取${key}属性`)
      return value
    }
  })
}

export function test () {
  const p = new Person('Tom')
  console.log(p.name)
  p.name = 'Jack'
  console.log(p.name)
}
